//
//  ScanViewController.m
//  sdfasdf
//
//  Created by Sumit Kumar Kasaudhan on 04/12/12.
//  Copyright (c) 2012 Mobicules Technologies. All rights reserved.
//

#import "ScanViewController.h"

@interface ScanViewController ()

@end

@implementation ScanViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    MBProgressHUD *hud = [MBProgressHUD  showHUDAddedTo:self.navigationController.view
                                               animated:YES];
    hud.labelText = @"Fetching";
    
    modal = [[ModalController  alloc] init];
    modal.delegate = self;
    [modal sendTheRequestWithPostString:nil withURLString:[NSString stringWithFormat:@"http://gilrob.com.au/iphone/sites.php?last_updated=2012-09-24%2006:02:37"]];
    
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}
-(void)getdata
{
    [MBProgressHUD  hideHUDForView:self.navigationController.view
                          animated:YES];
//    NSLog(<#NSString *format, ...#>)
//    iSDKLog(@"%@",moda,..);
    NSLog(@"~~~~~~%@",modal.stringRx);
    NSArray *arraySites = [modal.stringRx  componentsSeparatedByString:@"<br>"];
    NSLog(@"%@",arraySites);
    
    sites = [[NSMutableArray alloc] init];
    for(NSString *str in arraySites)
    {
        if([str rangeOfString:@"|"].length>0)
        {
            NSMutableDictionary *dic = [[NSMutableDictionary  alloc] init];
            [dic setObject:[[str componentsSeparatedByString:@"|"]objectAtIndex:0] forKey:@"id"];
            [dic setObject:[[str componentsSeparatedByString:@"|"]objectAtIndex:1] forKey:@"name"];
            
            [sites  addObject:dic];
            
        }
    }
    [tblview reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [sites  count];
}

// Row display. Implementers should *always* try to reuse cells by setting each cell's reuseIdentifier and querying for available reusable cells with dequeueReusableCellWithIdentifier:
// Cell gets various attributes set automatically based on table (separators) and data source (accessory views, editing controls)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:@"BaseCell"];
    if (!cell)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
                                       reuseIdentifier:@"BaseCell"] autorelease];
    }
    cell.accessoryType = 1;
    
    cell.textLabel.text = [[sites  objectAtIndex:indexPath.row] objectForKey:@"name"];
    return cell;
    
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView            
{
    return 1;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.section == 0)
    {
        ScanViewController *controller = [[ScanViewController  alloc] init];
        [self.navigationController  pushViewController:controller
                                              animated:YES];
        
    }
}


-(void)getError
{
    [MBProgressHUD  hideHUDForView:self.navigationController.view
                          animated:YES];
    [ModalController  FuncAlertMsg:@"Error in NetWork" 
                      inController:self];

}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
